
/***************************************************************************************************
 *
 * Project: HZFlashcards
 *
 * Class: FlashcardsMenuBar
 *
 * File name: FlashcardsMenuBar.java
 *
 * Created: Aug 22, 2007
 *
 *    $URL: file:///C:/Documents%20and%20Settings/All%20Users/Documents/Development/Eclipse_SVNRepository/HZFlashcards/src/com/eastmountain/chinese/gui/FlashcardsMenuBar.java $:
 *
 *    $Rev: 75 $:
 *    $Date: 2007-09-30 14:11:59 -0400 (Sun, 30 Sep 2007) $:
 *
 *    $LastChangedBy: ChaoChou $:
 *
 **************************************************************************************************/

package com.eastmountain.chinese.gui.controllers;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.Observable;
import java.util.Observer;

import javax.swing.Box;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

import com.eastmountain.chinese.gui.HTMLListPane;
import com.eastmountain.chinese.observable.HZFlashcardsDataModel;

@SuppressWarnings("serial")
public class HTMLMenuBar extends JMenuBar
                               implements Observer, ActionListener {

    private HZFlashcardsDataModel hzFlashcardsDataModel;

    private HTMLListPane htmlListPane;

    private String newline = "\n";

    // File actions

    private static final String FILE     =  "File";

    private static final String SAVE     =  "Save...";
    private static final String PRINT     =  "Print...";

    private static final String REVIEW_LIST        = "Review List";
    private static final String CHARACTER_WORD_XRF = "Character/Word XRF";

    /*************************************************
    *
    *   HTMLMenuBar()
    *
    **************************************************/

    public HTMLMenuBar( HTMLListPane htmlListPane ) {

        this.htmlListPane = htmlListPane;

        System.out.println( "\nHTMLMenuBar() invoked\n" );

        // TODO probably don't need the model
        //      since this is only a control thing

        hzFlashcardsDataModel = HZFlashcardsDataModel.getInstance();
        hzFlashcardsDataModel.addObserver( this );

        constructMenus();

    }

    public void constructMenus() {

        JMenu menu, subMenu;
        JMenuItem menuItem;

        System.out.println( "\nHTMLMenuBar.constructMenus() invoked\n" );

        // Build the first menu.

       /**************************************************
        *   File menu
        **************************************************/

        menu = new JMenu( HTMLMenuBar.FILE );
        menu.setMnemonic( KeyEvent.VK_F );
        menu.getAccessibleContext().setAccessibleDescription(
                        "The only menu in this program that has menu items" );
        add( menu );

        // a group of JMenuItems

        menuItem = new JMenuItem( HTMLMenuBar.SAVE );
        menuItem.setMnemonic( KeyEvent.VK_S );
        menuItem.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_S, ActionEvent.ALT_MASK ) );
        menuItem.addActionListener( this );
        menu.add( menuItem );


        menuItem = new JMenuItem( HTMLMenuBar.PRINT );
        menuItem.setMnemonic( KeyEvent.VK_O );
        menuItem.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_O, ActionEvent.ALT_MASK ) );
        menuItem.addActionListener( this );
        menu.add( menuItem );

        add( Box.createRigidArea( new Dimension( 5, 0 ) ) );

    }

    public void actionPerformed( ActionEvent e ) {

        JMenuItem item = (JMenuItem) e.getSource();

            /**************************************************
             *   File menu
             **************************************************/

            /**************************************************
             *   Save action
             **************************************************/

           if ( HTMLMenuBar.SAVE.equals( item.getText() ) ) {

               System.out.println( "------- HTMLMenuBar.actionPerformed()"
                                   + " - action = " + item.getText() );

               htmlListPane.writeHTML();

            /**************************************************
             *   Print action
             **************************************************/

           } else if ( HTMLMenuBar.PRINT.equals( item.getText() ) ) {

               System.out.println( "------- HTMLMenuBar.actionPerformed()"
                                   + 		" - action = " + item.getText() );

               htmlListPane.printHTML();

           }

    }

    public void update( Observable o, Object arg ) {

        /*************************************************
         *
         *   update
         *
         *************************************************/

    }

}
